﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using NewRetail.Application.Components.Platform;
using NewRetail.Application.Components.Platform.Model;
using NewRetail.Application.Components.Warehouse;
using NewRetail.Application.Core;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace NewRetail.Api.Controllers
{
    [NewRetailRoute("supplier-settlement")]
    public class SupplierSettlementController : BaseController
    {
        //private readonly IWarehouseGoodsService warehouseGoodsService;
        private readonly ISupplierSettlementService supplierSettlementService;
        private readonly ILogger _logger;

        public SupplierSettlementController(/*IWarehouseGoodsService warehouseGoodsService, */ISupplierSettlementService supplierSettlementService, 
            ILogger<SupplierSettlementController> logger)
        {
            //this.warehouseGoodsService = warehouseGoodsService;
            this.supplierSettlementService = supplierSettlementService;
            _logger = logger;
        }

        #region 供应商统一结算报表
        [HttpPost("query-supplierunifiedsettlement")]
        public async Task<ResponseEntity<IEnumerable<SupplierUnifiedSettlementShowDto>>> GetSupplierUnifiedSettlement([FromBody] QueryInOutWarehouseDto inputDto)
        {
            var ret = new ResponseEntity<IEnumerable<SupplierUnifiedSettlementShowDto>>();
            try
            {
                var result = await this.supplierSettlementService.GetSupplierUnifiedSettlementInfo(inputDto);
                ret.SetData(result);
            }
            catch (Exception e)
            {
                ret.SetError("失败！" + e.Message);
                _logger.LogError(e.Message);
            }

            return ret;
        }
        #endregion

        #region 单供应商结算报表
        [HttpPost("query-suppliersinglesettlement")]
        public async Task<ResponseEntity<IEnumerable<SupplierSingleSettlementShowDto>>> GetSupplierSingleSettlement([FromBody] QuerySingleSettlementDto inputDto)
        {
            var ret = new ResponseEntity<IEnumerable<SupplierSingleSettlementShowDto>>();
            try
            {
                var result = await this.supplierSettlementService.GetSupplierSingleSettlementInfo(inputDto);
                ret.SetData(result);
            }
            catch (Exception e)
            {
                ret.SetError("失败！" + e.Message);
                _logger.LogError(e.Message);
            }

            return ret;
        }
        #endregion
    }
}
